package com.zs.order.web;

import com.zs.order.pojo.Order;
import com.zs.order.service.OrderService;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * @projectName: hmall-parent
 * @package: com.zs.order.web
 * @className: OrderController
 * @author: zs
 * @description:
 * @date: 2023/5/12 21:41
 * @version: 1.0
 */
@RestController
@RequestMapping("order")
public class OrderController {

    @Autowired
    private OrderService orderService;
    @Autowired
    private RabbitTemplate rabbitTemplate;

    @GetMapping("{orderId}")
    public Order queryOrderByUserId(@PathVariable("orderId") Long orderId) {
        // 根据id查询订单并返回
        Order order = orderService.queryOrderById(orderId);
        //通知用户其订单成功
        Map<String,Object> map=new HashMap<>();
        map.put("orderId",order.getId());
        map.put("userId",order.getUserId());
        map.put("name",order.getName());

        rabbitTemplate.convertAndSend("itcast.order","order",map);
        return order;
    }
}